#include "BackgroundPicture.h"

BackgroundPicture::BackgroundPicture(string picType,string picName,Ogre::SceneNode* picRootNode,float scale,Ogre::SceneManager * sm)
{
	//test
	//cout<<"Pictrue construct execute first"<<endl;
	//test

	this->_picType = picType;
	this->_picName = picName;
	this->_picRootNode = picRootNode;
	this->_scale = scale;
	this->_sm = sm;

	this->_picNode = this->_picRootNode->createChildSceneNode(this->_picName);

	this->_picManual = this->_sm->createManualObject(this->_picName);

	this->_picManual->begin(this->_picType, Ogre::RenderOperation::OT_TRIANGLE_LIST);
	//this->_picManual->begin("MyMaterial2", Ogre::RenderOperation::OT_TRIANGLE_LIST);

	_picManual->position(5.0, 0.0, 0.0);
	_picManual->textureCoord(1,1);
	_picManual->position(-5.0, 10.0, 0.0);
	_picManual->textureCoord(0,0);
	_picManual->position(-5.0, 0.0, 0.0);
	_picManual->textureCoord(0,1);
	_picManual->position(5.0, 10.0, 0.0);
	_picManual->textureCoord(1,0);

	_picManual->index(0);
	_picManual->index(1);
	_picManual->index(2);
	_picManual->index(0);
	_picManual->index(3);
	_picManual->index(1);

	_picManual->end();
	_picManual->convertToMesh(this->_picName);

	this->_picEntity = this->_sm->createEntity(this->_picName);

	this->_picEntity->setQueryFlags(0);

	this->_picNode->attachObject(this->_picEntity);

	this->_picNode->yaw(Ogre::Degree(180.0f));

	this->_picNode->pitch(Ogre::Degree(-20.0f));

	this->_picNode->setScale(Ogre::Vector3(this->_scale,this->_scale,this->_scale));

	this->_picNode->setVisible(false);
	//this->_picNode->setScale(Ogre::Vector3(15.0,15.0,15.0));

	//test
	//cout<<"Pictrue construct execute"<<endl;
	//test

	//this->_picNode->setVisible(true);

}

void BackgroundPicture::setVisable(bool visable)
{
	this->_picNode->setVisible(visable);
}

void BackgroundPicture::translate(Ogre::Vector3 translate)
{
	this->_picNode->translate(translate);
}

string BackgroundPicture::getPicName()
{
	return this->_picName;
}

void BackgroundPicture::setScale(float x,float y,float z)
{
	this->_picNode->setScale(Ogre::Vector3(x,y,z));
}

void BackgroundPicture::setManualPos(float x,float y)
{
	_picManual->position(x, 0.0, 0.0);
	_picManual->textureCoord(1,1);
	_picManual->position(-x, y, 0.0);
	_picManual->textureCoord(0,0);
	_picManual->position(-x, 0.0, 0.0);
	_picManual->textureCoord(0,1);
	_picManual->position(x, y, 0.0);
	_picManual->textureCoord(1,0);

}

BackgroundPicture::~BackgroundPicture(void)
{
}
